integer function F_readnext(co,x,y,z,skip0)
  use iso_c_binding, only: c_char,c_float,c_int
  implicit none
    real(4) :: co(:),x(:),y(:),z(:)
    logical, optional :: skip0
    interface
         subroutine C_readnext(step,co,x,y,z,skip) bind(C, name="readNextStep")
            use iso_c_binding, only: c_float,c_int
            real(kind=c_float) :: co(*),x(*),y(*),z(*)
            integer(kind=c_int) :: skip,step
        end subroutine C_readnext
    end interface
    real(kind=c_float), ALLOCATABLE :: x0(:),y0(:),z0(:),co0(:)
    integer n,nco,o,skip,step


    if(present(skip0)) then
        if(skip0) then
            skip=1
        else
            skip=0
        endif
    else
        skip=0
    endif

    n=size(x);nco=size(co)
    allocate (x0(n),y0(n),z0(n),co0(nco))
    call C_readnext(step,co0,x0,y0,z0,skip)
    if(step .lt. 0) then
        write(*,*) " Cannot read beyond end of file !!!! "
        F_readnext=step;
        return
    endif
    do o=1,n
        x(o)=x0(o)
        y(o)=y0(o)
        z(o)=z0(o)
    enddo
    do o=1,nco
        co(o)=co0(o)
    enddo
    F_readnext=step;
end function F_readnext
